package com.my.util.execl;

import cn.hutool.crypto.SecureUtil;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.my.entity.GradeClass;
import com.my.entity.User;
import com.my.service.GradeClassService;
import com.my.service.UserService;
import com.my.util.execl.entity.StudentExcel;
import com.my.util.execl.entity.TeacherExcel;

public class TeacherExcelListener extends AnalysisEventListener<TeacherExcel> {

    private UserService service;

    private GradeClassService gcService;

    public TeacherExcelListener(UserService service, GradeClassService gcService) {
        this.service = service;
        this.gcService = gcService;
    }

    @Override
    public void invoke(TeacherExcel excel, AnalysisContext analysisContext) {
        User user = new User();
        user.setId(excel.getId());
        user.setName(excel.getName());
        user.setPhone(excel.getPhone());
        user.setAddress(excel.getAddress());
        user.setSex("女".equals(excel.getSex()) ? 0 : 1);
        user.setType("老师".equals(excel.getType()) ? 1 : 2);
        service.save(user);
        user.setPassword(SecureUtil.md5(user.getId() + user.getPassword()));
        service.updateById(user);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) { }
}
